package simbot.example.utils.pixiv;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Value;

import simbot.example.utils.client.HttpClientUtil;
import simbot.example.utils.pixiv.dto.PixivDTO;


import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 祺诺
 * @Name; 谢钱枫 1053557904@qq.com
 * @Date: 2021/6/10 15:12
 */
public class PixivUtil {
    @Value("${pixiv.proxy}")
    private static String proxy;
    /**
     * 随机色图
     * @return
     */
    public static PixivDTO getRandomHImage(){
        String url = "https://api.lolicon.app/setu/v2?size=small&size=original";
        Map<String,Object> params = new HashMap<>();
        //params.put("r18","1");
        String s = HttpClientUtil.sendPost(url, params);
        PixivDTO pixivDTO = JSON.parseObject(s, PixivDTO.class);
        return pixivDTO;
    }


    /**
     * R18图
     * @return
     */
    public static PixivDTO getR18(){
        String url = "https://api.lolicon.app/setu/v2?size=small&size=original";
        Map<String,Object> params = new HashMap<>();
        params.put("r18","1");
        String s = HttpClientUtil.sendPost(url, params);
        PixivDTO pixivDTO = JSON.parseObject(s, PixivDTO.class);
        return pixivDTO;
    }

    /**
     * 搜图
     *
     * @param res
     * @return
     */
    public static PixivDTO getImage(String res) {
        String url = "https://api.lolicon.app/setu/v2?size=small&size=original&tag="+res;
        String s = HttpClientUtil.sendGet(url);
        PixivDTO pixivDTO = JSON.parseObject(s, PixivDTO.class);
        return pixivDTO;
    }

    /**
     * 搜图
     *
     * @param res
     * @return
     */
    public static PixivDTO getHImage(String res) {
        String url = "https://api.lolicon.app/setu/v2?size=small&size=original&r18=1&tag="+res;
        String s = HttpClientUtil.sendGet(url);
        PixivDTO pixivDTO = JSON.parseObject(s, PixivDTO.class);
        return pixivDTO;
    }
}
